/* vim: set ft=cpp et: */
%%
headers
#include <atk/atk.h>
#include <atk/atk-enum-types.h>
#include <atk/atknoopobjectfactory.h>
#include <atk/atknoopobject.h>

%%
ignore-glob
    *_get_type

%% {{{ AtkRelation

%%
add-arginfo AtkRelation __construct
PHPGTK_ARG_INFO_STATIC
ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
    ZEND_ARG_INFO(0, targets)
    ZEND_ARG_INFO(0, relationship)
ZEND_END_ARG_INFO();

%%
override atk_relation_new
PHP_METHOD
{
	zval *php_targets, *php_relationship = NULL;
	gint n_targets, i = 0;
	AtkRelationType relationship;
	AtkObject **targets = NULL;
	zval **temp_target;
	GObject *wrapped_obj = NULL;

	if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "aV", &php_targets, &php_relationship)) {
		PHPG_THROW_CONSTRUCT_EXCEPTION(AtkRelationObject);
	}

	if (php_relationship && phpg_gvalue_get_enum(ATK_TYPE_RELATION_TYPE, php_relationship, (gint *)&relationship) == FAILURE) {
		PHPG_THROW_CONSTRUCT_EXCEPTION(AtkRelationObject);
	}

	n_targets = zend_hash_num_elements(Z_ARRVAL_P(php_targets));
	targets = safe_emalloc(n_targets+1, sizeof(AtkObject *), 0);

	zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_targets));
	while (zend_hash_get_current_data(Z_ARRVAL_P(php_targets), (void **)&temp_target) == SUCCESS) {
		targets[i] = ATK_OBJECT(PHPG_GOBJECT(*temp_target));
		zend_hash_move_forward(Z_ARRVAL_P(php_targets));
		i++;
	}

	wrapped_obj = (GObject *) atk_relation_new(targets, n_targets, relationship);
	efree(targets);

	if (!wrapped_obj) {
		PHPG_THROW_CONSTRUCT_EXCEPTION(AtkRelationObject);
	}
	phpg_gobject_set_wrapper(this_ptr, wrapped_obj TSRMLS_CC);
}

%% }}}
